<?php

namespace app\index\traits;

use app\common\service\DouyinMiniProgramMessageService;
use app\common\service\MiniProgramMessageService;
use app\common\service\SubscribeMessageService;
use think\facade\Request;

/**
 * 微信公众号模板消息
 * Trait SubscribeMessageTemplateTrait
 * @package app\index\traits
 */
trait SubscribeMessageTemplateTrait
{

    /**
     * 创建咨询
     * @return array
     */
    private function getConsultingSubscribeMessageTemplates(): array
    {
        $pf = Request::header('pf');

        // 返回客户端订阅消息
        $subscribe_message_templates = [];
        $service = $this->getSubscribeMessageService($pf);
        if ($service) {
            $subscribe_message_templates = $service->getConsultingTemplates();
        }
        return $subscribe_message_templates;
    }

    private function getSubscribeMessageService($pf): ?SubscribeMessageService
    {
        if ($pf == PT_WX) {
            return \app(MiniProgramMessageService::class);
        }

        if ($pf == PT_TT) {
            return \app(DouyinMiniProgramMessageService::class);
        }

        return null;
    }
}